package com.yexs.controller;

import com.yexs.beans.MyInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@EnableConfigurationProperties({MyInfo.class})
public class HelloController {

    @Value("${myinfo.name}")
    String name;
    @Autowired
    private MyInfo myInfo;
    @Resource
    private Environment env;

    /**
     * 资源文件的 都被设置到环境变量了
     */
    public void getValue() {
        String name = env.getRequiredProperty("myinfo.name");
    }

    @RequestMapping("/")
    public String index() {
        System.out.println(name);
//        return "Greetings from Spring Boot!";
        return "<h3 style='color:red'>Hello " + myInfo.getName() + " age:" + myInfo.getAge() + " 随机数： " + myInfo.getNumber() + " ,</h3><h4>hello springBoot</h4>";
    }
}
